package com.xsmart.oa.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 分销商相关操作
 *
 * @author guojd
 */
@Component
public interface DistributorDao {
    /**
     * 查询会员所属分销商
     *
     * @param uid 会员ID
     * @return 分销商id
     */
    @Select("SELECT * FROM infu_distributor_member WHERE user_id=#{uid} LIMIT 1")
    Map<String, Object> queryDistributorByUid(@Param("uid") Integer uid);

    /**
     * 查询分销商店铺
     * @param duid 分销商id
     * @return 店铺信息
     */
    @Select("select * from seller_shopinfo where ru_id=#{duid}")
    Map<String, Object> queryDistributorSellerByDuid(@Param("duid") Integer duid);

    /**
     * 会员绑定分销商
     * @param uid 会员id
     * @param duid 分销商id
     * @return 影响记录数
     */
    @Insert("INSERT INTO infu_distributor_member(user_id, d_user_id) VALUES(#{uid},#{duid})")
    int relDistributorAndMember(@Param("uid") Integer uid, @Param("duid") Integer duid);

    /**
     * 添加分享记录
     * @param shareLog 分享信息
     * @return 影响记录数
     */
    @Insert("INSERT INTO infu_share_log(share_id,share_user_id)VALUES (#{shareId},#{uid})")
    int addShareLog(Map<String,Object> shareLog);

    /**
     * 查询分享记录
     * @param shareUserId 分享用户id
     * @return 分享记录
     */
    @Select("select * from infu_share_log where share_user_id=#{shareUserId}")
    List<Map<String,Object>> queryShareLog(@Param("shareUserId") Integer shareUserId);

    /**
     * 分享注册用户记录
     * @param shareRegLog 分享注册用户记录
     * @return 影响记录数
     */
    @Insert("INSERT INTO infu_share_reg_log(share_id, reg_user_id) values(#{shareId},#{regUserId})")
    int addShareRegLog(Map<String,Object> shareRegLog);

    @Select("select * from infu_share_reg_log srl ")
    List<Map<String,Object>> queryShareRegLog(String shareId,Integer shareUserId);

    /**
     * 查询会员类型
     * @param userId 会员id
     * @return
     */
    @Select("select user_type from INFS_USER where user_id = #{userId}")
    List<Integer> queryUserType(@Param("userId") Integer userId);
}